package com.yimi.yinhepda.adapter.RecycleAdapter

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import com.yimi.yinhepda.R
import com.pda.ym.base.CommonRecycleAdapter
import com.pda.ym.base.CommonViewHolder
import com.yimi.yinhepda.entity.bean.KuaYueTaskEntity
import com.pda.ym.utils.DateHelper

/**
 * @author: lj
 * Description:跨越任务列表适配器
 */
class KuaYueTaskAdapter(var context: Context?, dataList: MutableList<KuaYueTaskEntity>?, var commonClickListener: CommonViewHolder.onItemCommonClickListener?)
    : CommonRecycleAdapter<KuaYueTaskEntity>(context, dataList, R.layout.item_kua_yue_task) {

    override fun bindData(holder: CommonViewHolder?, data: KuaYueTaskEntity?, position: Int) {
        holder?.setCommonClickListener(commonClickListener)
        holder?.setText(R.id.tv_taskNo, data?.taskNo)
        holder?.setText(R.id.tv_prevStation, data?.departName)
        holder?.setText(R.id.tv_carNo, data?.carNo)
        holder?.setText(R.id.tv_piaoNum, data?.priceNum.toString())

        if (data?.isCheck!!) {
            holder?.itemView?.setBackgroundColor(context!!.resources.getColor(R.color.yellow))
        } else {
            holder?.itemView?.setBackgroundColor(context!!.resources.getColor(R.color.white))
        }

        val carNo = holder?.getView<TextView>(R.id.tv_carNo)
        carNo?.setOnClickListener {
            showDriverDialog(data)
        }
    }

    /**
     * 司机信息
     */
    private fun showDriverDialog(data: KuaYueTaskEntity?) {
        val layout = LayoutInflater.from(context).inflate(R.layout.alert_dialog_kuayue_car_info, null) as LinearLayout
        //司机姓名
        val tvDriverName = layout.findViewById<TextView>(R.id.tv_driver_name)
        //司机电话
        val tvDriverPhone = layout.findViewById<TextView>(R.id.tv_driver_phone)
        //出发时间
        val tvStartTime = layout.findViewById<TextView>(R.id.tv_start_time)
        val btnOk = layout.findViewById<Button>(R.id.btn_ok)
        val dialog = Dialog(context, R.style.AsyncTaskDialog)
        dialog.addContentView(layout, LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT))
        dialog.window.setBackgroundDrawableResource(android.R.color.transparent)
        dialog.window.decorView.setPadding(10, 0, 10, 0)
        dialog.setCanceledOnTouchOutside(false)
        dialog.show()

        tvDriverName.text = "司机姓名：${data?.driverName}"
        tvDriverPhone.text = "司机电话：${data?.driverPhone}"
        tvStartTime.text = "出发时间：${DateHelper.formatTimeEight(data?.departTime)}"

        btnOk.setOnClickListener {
            dialog.dismiss()
        }
    }
}